package com.li.algorithm.leetcode.hot100;

public class Test37 {
    int max = Integer.MIN_VALUE;
    int count = 0;
    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        //左，右，中
        count++;
        if (root.left != null) {
            maxDepth(root.left);
        }
        if (root.right != null) {
            maxDepth(root.right);
        }
        max = Math.max(count, max);
        count--;
        return max;
    }

    public static void main(String[] args) {
        // 创建各个节点
        TreeNode node9 = new TreeNode(9);
        TreeNode node15 = new TreeNode(15);
        TreeNode node7 = new TreeNode(7);
        TreeNode node20 = new TreeNode(20, node15, node7);
        TreeNode node3 = new TreeNode(3, node9, node20);

        int result = new Test37().maxDepth(node3);
        System.out.println(result);

    }
}
